package de.reichelt.fxrequi.data;

import de.reichelt.fx.FxOption;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Testcase {
  private final IntegerProperty id = new SimpleIntegerProperty();
  private final IntegerProperty testpackId = new SimpleIntegerProperty();
  private final IntegerProperty reqId = new SimpleIntegerProperty();
  private final StringProperty reqCounter = new SimpleStringProperty();
  private final StringProperty reqTitle = new SimpleStringProperty();
  private final StringProperty nr = new SimpleStringProperty();
  private final ObjectProperty<FxOption> priority = new SimpleObjectProperty<>();
  private final StringProperty descr = new SimpleStringProperty();
  private final StringProperty configuration = new SimpleStringProperty();
  private final StringProperty preCondition = new SimpleStringProperty();
  private final StringProperty postCondition = new SimpleStringProperty();
  private final StringProperty testScript = new SimpleStringProperty();
  private final StringProperty keywords = new SimpleStringProperty();
  private final ObjectProperty<Date> dateCreated = new SimpleObjectProperty<>();
  private final StringProperty userCreated = new SimpleStringProperty();
  
  public static List<FxOption> priorities = Arrays.asList(
          new FxOption("low", "niedrig"), 
          new FxOption("middle", "mittelhoch"), 
          new FxOption("high", "hoch"));

  public Testcase() {
  }

  public Testcase(Integer id, Integer testpackId, Integer reqId, String reqCounter,
          String reqTitle, String nr, FxOption priority, String descr, String configuration,
          String preCondition, String postCondition, String testScript,
          String keywords, Date dateCreated, String userCreated) {
    setId(id);
    setTestpackId(testpackId);
    setReqId(reqId);
    setReqCounter(reqCounter);
    setReqTitle(reqTitle);
    setNr(nr);
    setPriority(priority);
    setDescr(descr);
    setConfiguration(configuration);
    setPreCondition(preCondition);
    setPostCondition(postCondition);
    setTestScript(testScript);
    setKeywords(keywords);
    setDateCreated(dateCreated);
    setUserCreated(userCreated);
  }
  
  
  public int getId() {
    return id.get();
  }

  public void setId(int value) {
    id.set(value);
  }

  public IntegerProperty idProperty() {
    return id;
  }
  
  public int getTestpackId() {
    return testpackId.get();
  }

  public void setTestpackId(int value) {
    testpackId.set(value);
  }

  public IntegerProperty testpackIdProperty() {
    return testpackId;
  }
  
  public String getNr() {
    return nr.get();
  }

  public void setNr(String value) {
    nr.set(value);
  }

  public StringProperty nrProperty() {
    return nr;
  }
  
  public int getReqId() {
    return reqId.get();
  }

  public void setReqId(int value) {
    reqId.set(value);
  }

  public IntegerProperty reqIdProperty() {
    return reqId;
  }
  
  public String getReqCounter() {
    return reqCounter.get();
  }

  public void setReqCounter(String value) {
    reqCounter.set(value);
  }

  public StringProperty reqCounterProperty() {
    return reqCounter;
  }
  
  public String getReqTitle() {
    return reqTitle.get();
  }

  public void setReqTitle(String value) {
    reqTitle.set(value);
  }

  public StringProperty reqTitleProperty() {
    return reqTitle;
  }
  
  public FxOption getPriority() {
    return priority.get();
  }

  public void setPriority(FxOption value) {
    priority.set(value);
  }

  public ObjectProperty priorityProperty() {
    return priority;
  }
  
  public String getDescr() {
    return descr.get();
  }

  public void setDescr(String value) {
    descr.set(value);
  }

  public StringProperty descrProperty() {
    return descr;
  }
  
  public String getConfiguration() {
    return configuration.get();
  }

  public void setConfiguration(String value) {
    configuration.set(value);
  }

  public StringProperty configurationProperty() {
    return configuration;
  }
  
  public String getPreCondition() {
    return preCondition.get();
  }

  public void setPreCondition(String value) {
    preCondition.set(value);
  }

  public StringProperty preConditionProperty() {
    return preCondition;
  }
  
  public String getPostCondition() {
    return postCondition.get();
  }

  public void setPostCondition(String value) {
    postCondition.set(value);
  }

  public StringProperty postConditionProperty() {
    return postCondition;
  }
  
  public String getTestScript() {
    return testScript.get();
  }

  public void setTestScript(String value) {
    testScript.set(value);
  }

  public StringProperty testScriptProperty() {
    return testScript;
  }
  
  public String getKeywords() {
    return keywords.get();
  }

  public void setKeywords(String value) {
    keywords.set(value);
  }

  public StringProperty keywordsProperty() {
    return keywords;
  }
  
  public Date getDateCreated() {
    return dateCreated.get();
  }

  public void setDateCreated(Date value) {
    dateCreated.set(value);
  }

  public ObjectProperty dateCreatedProperty() {
    return dateCreated;
  }
  
  public String getUserCreated() {
    return userCreated.get();
  }

  public void setUserCreated(String value) {
    userCreated.set(value);
  }

  public StringProperty userCreatedProperty() {
    return userCreated;
  }
  
  public static FxOption getPriority(String key) {
    for (FxOption opt: priorities) {
      if (opt.getKey().equals(key)) {
        return opt;
      }
    }
    return null;
  }
  
  public static FxOption getPriorityByValue(String value) {
    for (FxOption opt: priorities) {
      if (opt.getValue().equals(value)) {
        return opt;
      }
    }
    return null;
  }

  @Override
  public String toString() {
    return reqCounter + "-" + nr + ": " + reqTitle;
  }
  
  
  
  
}
